<template>
  <el-dialog :title="titleMap[mode]" v-model="visible" width="85%"
             destroy-on-close @closed="$emit('closed')" align-center>
    <el-container>
      <el-header>
        <div class="left-panel">
          <el-button type="primary" @click="back">{{$t('all.confirm')}}</el-button>
        </div>
        <div class="right-panel">
          <div class="right-panel-search">
            <el-input v-model="search.goods_name" :placeholder="$t('goods.goods.name')" clearable @keyup.enter="upsearch"></el-input>
            <el-input v-model="search.goods_code" :placeholder="$t('goods.goods.code')" clearable @keyup.enter="upsearch"></el-input>
            <el-input v-model="search.goods_spec" :placeholder="$t('goods.goods.spec')" clearable @keyup.enter="upsearch"></el-input>
            <el-input v-model="search.goods_model" :placeholder="$t('goods.goods.model')" clearable @keyup.enter="upsearch"></el-input>
            <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
            <el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
          </div>
        </div>
      </el-header>
      <el-main class="nopadding">
        <scTable ref="table" row-key="id" :apiObj="apiObj" @row-click="selectionChange" stripe remoteSort remoteFilter border height="650">
          <el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
          <el-table-column type="index" width="50" align="center"></el-table-column>
          <el-table-column label="采购入库单号" prop="purchase_code" align="center"></el-table-column>
          <el-table-column :label="$t('sale.sale.date')" prop="open_date" align="center"></el-table-column>
          <el-table-column :label="$t('procure.order.code')" prop="purchase.code" align="center"></el-table-column>
          <el-table-column :label="$t('procure.house.indate')" prop="entry_date" align="center"></el-table-column>
          <el-table-column :label="$t('all.remark')" prop="remark" align="center"></el-table-column>
          <el-table-column :label="$t('procure.house.consignee')" prop="collect_staff" align="center"></el-table-column>
          <el-table-column :label="$t('all.createadmin')" prop="admin.name" align="center"></el-table-column>
          <el-table-column :label="$t('all.createtime')" prop="create_time" align="center"></el-table-column>
        </scTable>
      </el-main>
    </el-container>
    <template #footer>
      <el-button @click="visible = false">{{$t('all.cancel')}}</el-button>
    </template>
  </el-dialog>
</template>

<script>
export default {
  emits: ['success', 'closed'],
  data() {
    return {
      mode: "add",
      titleMap: {
        add: '选择采购入库单',
        edit: '编辑产品',
        show: '查看'
      },
      visible: false,
      isSaveing: false,
      apiObj: this.$API.procure.inorder.list,
      selection: [],
      search: {
        goods_name: null,
        goods_code: null,
        goods_spec: null,
        goods_model: null,
        material_code: null,
      },
      data: []
    }
  },
  mounted() {
    this.getShop()
  },
  methods: {
    // 显示
    open(mode = 'add') {
      this.mode = mode;
      this.visible = true;
      return this
    },
    // 表单注入数据
    setData(data) {
      this.type = data
    },
    // 选择事件
    selectionChange(selection) {
      // this.selection = selection;
      this.$emit('success', selection)
      this.visible = false;
    },
    // 选中返回
    back() {
      this.$emit('success', this.selection, this.type)
      this.visible = false;
    },
    //搜索
    upsearch() {
      this.$refs.table.upData(this.search)
    },
    refresh() {
      for (const key in this.search) {
        this.search[key] = null;
      }
      this.$refs.table.upData(this.search)
    },
    async getShop() {
      var res = await this.$API.procure.plan.shop.get();
      this.data = res.data
    },
  }
}
</script>

<style></style>
